//
//  DoctorInfoViewController.m
//  QuickCure
//
//  Created by 凉气的Mac on 16/9/12.
//  Copyright © 2016年 haoge. All rights reserved.
//

#import "DoctorInfoViewController.h"

#import "FocusDoctorTableViewCell.h"

#import "FocusDoctorViewButton.h"

#import "DoctorInfoHeaderView.h"

#import "ConditionTableView.h"

#import "DoctorInfoTableView.h"

static NSString *resureId = @"cell";

@interface DoctorInfoViewController ()<UIScrollViewDelegate>

/**
 *  顶部医生信息
 */
@property(nonatomic,weak) DoctorInfoHeaderView *headerView;

/**
 *  医生头像
 */
@property(nonatomic,weak) UIImageView *doctorIcon;

@property(nonatomic,strong)  NSMutableArray *btnArray;

@property(nonatomic,strong)  NSMutableArray *centerBtnArray;

/**
 *  当前选中的按钮
 */
@property(nonatomic,weak) UIButton *selectButton;

@property(nonatomic,weak) UIImageView *lineImageView;

/**
 *  中间的scrollView
 */
@property(nonatomic,weak) UIScrollView *scrollView;

@end

@implementation DoctorInfoViewController

-(NSMutableArray *)btnArray{
    
    if (_btnArray == nil) {
        
        _btnArray = [NSMutableArray array];
        
    }
    
    return _btnArray;
}

-(NSMutableArray *)centerBtnArray{
    
    if (_centerBtnArray == nil) {
        
        _centerBtnArray = [NSMutableArray array];
        
    }
    
    return _centerBtnArray;
}


-(void)setModel:(FocusDoctorModel *)model{

    _model = model;
    
   
}



- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor colorWithWhite:0.95 alpha:1.000];
    
    //设置navigation
    [self setupNavigation];
    
    //设置顶部界面
    [self setupHeaderView];
    
    //设置中间按钮
    [self setupCenterView];
    
    //设置scrollView
    [self setupScrollView];
    
    //设置咨询按钮
    [self setupConsultBtn];
}

#pragma mark --
#pragma mark --设置Navigation
-(void)setupNavigation{

    self.title = @"医生基本信息";
    
    self.navigationController.navigationBar.translucent = NO;
    
    //添加右侧星号按钮
    UIButton *rightBtn = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 15, 15)];
    
    [rightBtn setBackgroundImage:[UIImage imageNamed:@"kongxin"] forState:UIControlStateNormal];
    
    [rightBtn setBackgroundImage:[UIImage imageNamed:@"shixin"] forState:UIControlStateSelected];
    
    [rightBtn addTarget:self action:@selector(clickRightItem:) forControlEvents:UIControlEventTouchUpInside];
    
    UIBarButtonItem *rightItem = [[UIBarButtonItem alloc]initWithCustomView:rightBtn];
    
    self.navigationItem.rightBarButtonItem = rightItem;
    
    
}

#pragma mark --
#pragma mark --点击左侧星号按钮
-(void)clickRightItem:(UIButton *)button{

    button.selected = !button.isSelected;
}

#pragma mark --
#pragma mark --设置顶部界面
-(void)setupHeaderView{

    DoctorInfoHeaderView *headerView = [[DoctorInfoHeaderView alloc]init];
    
    headerView.model = self.model;
    
    self.headerView = headerView;
    
    headerView.backgroundColor = [UIColor whiteColor];
    
    [self.view addSubview:headerView];
    
    [headerView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.left.right.equalTo(self.view);
        
        make.height.equalTo(self.view).multipliedBy(0.25);
        
    }];

    
}

#pragma mark --
#pragma mark --添加中间按钮
-(void)setupCenterView{
    
    UIButton *leftBtn = [self addBtnWithTitle:@"就诊条件"];
    
    leftBtn.tag = 0;
    
    [leftBtn mas_updateConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self.view);
        
    }];
    
    [leftBtn setTitleColor:[UIColor colorWithRed:0.053 green:0.755 blue:0.770 alpha:1.000] forState:UIControlStateNormal];
    
    self.selectButton = leftBtn;
    
    [self.centerBtnArray addObject:leftBtn];
    
    UIButton *rightBtn = [self addBtnWithTitle:@"医生简介"];
    
    rightBtn.tag = 1;
    
    [rightBtn mas_updateConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(leftBtn.mas_right);
        
    }];
    
    [self.centerBtnArray addObject:rightBtn];
    
    UIView *lineView = [[UIView alloc]init];
    
    lineView.backgroundColor = [UIColor colorWithWhite:0.800 alpha:1.000];
    
    [self.view addSubview:lineView];
    
    [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
    
        make.centerX.equalTo(self.view);
        
        make.width.equalTo(@1);
        
        make.top.equalTo(self.headerView.mas_bottom).offset(20);
        
        make.height.equalTo(@30);
    }];
    
    UIImageView *lineImageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"nav"]];
    
    self.lineImageView = lineImageView;
    
    [self.view addSubview:lineImageView];
    
    [lineImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.bottom.equalTo(leftBtn).offset(-5);
        
        make.height.equalTo(@2);
        
        make.width.equalTo(self.view).multipliedBy(0.3);
        
        make.centerX.equalTo(leftBtn);
        
    }];
    
    [self clickCenterBtn:leftBtn];

}

-(UIButton *)addBtnWithTitle:(NSString *)title{

    UIButton *button = [[UIButton alloc]init];
    
    [button setBackgroundColor:[UIColor whiteColor]];
    
    [button setTitle:title forState:UIControlStateNormal];
    
    button.titleLabel.font = [UIFont systemFontOfSize:20];
    
    [button addTarget:self action:@selector(clickCenterBtn:) forControlEvents:UIControlEventTouchUpInside];
    
    [button setTitleColor:[UIColor colorWithWhite:0.9 alpha:1.000] forState:UIControlStateNormal];
    
    [self.view addSubview:button];
    
    [button mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.headerView.mas_bottom).offset(4);
        
        make.width.equalTo(self.view).multipliedBy(0.5);
        
        make.height.equalTo(@60);
        
    }];
    
    return button;

    
}

#pragma mark --
#pragma mark --点击中部按钮
-(void)clickCenterBtn:(UIButton *)button{
    
    if (self.selectButton.tag == button.tag) {
        return;
    }

    [button setTitleColor:[UIColor colorWithRed:0.053 green:0.755 blue:0.770 alpha:1.000] forState:UIControlStateNormal];
    
    [self.selectButton setTitleColor:[UIColor colorWithWhite:0.9 alpha:1.000] forState:UIControlStateNormal];
    
    self.selectButton = button;
    
    [UIView animateWithDuration:0.2 animations:^{
        
        self.lineImageView.transform = CGAffineTransformMakeTranslation(button.center.x-90, 0);
        
    }];
    
    [self.scrollView setContentOffset:CGPointMake(button.tag * sWidth, 0) animated:YES];
    
}

#pragma mark --
#pragma mark --设置scrolView
-(void)setupScrollView{

    UIScrollView *scrollView = [[UIScrollView alloc]init];
    
    self.scrollView = scrollView;
    
    scrollView.delegate = self;
    
    [self.view addSubview:scrollView];
    
    scrollView.contentSize = CGSizeMake(sWidth * 2, 0);
    
    scrollView.showsHorizontalScrollIndicator = NO;
    
    scrollView.pagingEnabled = YES;

    [scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.right.bottom.equalTo(self.view);

        make.top.equalTo(self.headerView.mas_bottom).offset(70);
    }];

    ConditionTableView *condition = [[ConditionTableView alloc]initWithFrame:scrollView.bounds style:UITableViewStylePlain];
    
    [scrollView addSubview:condition];
    
    condition.backgroundColor = self.view.backgroundColor;
    
    [condition mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(self.view);
        make.bottom.equalTo(self.view).offset(-60);
        make.left.equalTo(scrollView);
        make.top.equalTo(self.headerView.mas_bottom).offset(70);
    }];
    
    
    DoctorInfoTableView *doctorInfo = [[DoctorInfoTableView alloc]initWithFrame:scrollView.bounds style:UITableViewStyleGrouped];
    
    [scrollView addSubview:doctorInfo];
    
    doctorInfo.backgroundColor = self.view.backgroundColor;
    
    [doctorInfo mas_makeConstraints:^(MASConstraintMaker *make) {

        make.width.bottom.equalTo(condition);
        make.left.equalTo(condition.mas_right);
        make.top.equalTo(condition);
        
    }];
    
    
}

#pragma mark --
#pragma mark --scrollView代理
-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{

    NSInteger index = scrollView.contentOffset.x / sWidth;
    
    UIButton *button = self.centerBtnArray[index];
    
    [self clickCenterBtn:button];
    
}


#pragma mark --
#pragma mark --设置底部咨询按钮
-(void)setupConsultBtn{
    
    UIView *tempView = [[UIView alloc]init];
    
    tempView.backgroundColor = [UIColor whiteColor];
    
    [self.view addSubview:tempView];
    
    [tempView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.right.bottom.equalTo(self.view);
        
        make.height.equalTo(@60);
        
    }];

    UIButton *consultBtn = [[UIButton alloc]init];
    
    [consultBtn setBackgroundImage:[UIImage imageNamed:@"nav"] forState:UIControlStateNormal];

    [consultBtn setTitle:@"咨询医生" forState:UIControlStateNormal];
    
    [consultBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    
    [tempView addSubview:consultBtn];
    
    [consultBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.left.equalTo(tempView).offset(10);
        
        make.bottom.right.equalTo(tempView).offset(-10);
    }];
}









@end









































